package com.wushi.lenovo.asia5b.app_model.h5;

import android.text.TextUtils;
import android.webkit.JavascriptInterface;

import com.mvp.dagger.modules.NetworkModule;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import timber.log.Timber;

/**
 * Created by zhangyuncai on 2018/11/27.
 */
public abstract class JsCall extends Object {

    //给html提供的有参函数，html调用我们这个方法 ： window.Android.HtmlcallJava2("IT-homer blog");
    @JavascriptInterface
    public void HtmlcallJava2(final String param) {
        NetworkModule.printJson(param);
        if (!TextUtils.isEmpty(param)) {
            Observable.just(param)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(s -> {
                        callbackParam(s);
                    });
        }
    }
    public abstract void callbackParam(String param);

    /**
     * 加载webview状态回调
     * @param param
     */
    @JavascriptInterface
    public void loadState(final String param) {
        Timber.d("--->>>>>>>>---loadState:"+param);
        if (!TextUtils.isEmpty(param)) {
            Observable.just(param)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(s -> {
                        loadStateByMain(s);
                    });
        }
    }

    /**
     * 加载webview状态回调,在主线程
     * @param param
     */
    public void loadStateByMain(final String param) {

    }

}
